package cn.edu.sgu.www.mhxysy.service.fabao.impl;

import cn.edu.sgu.www.mhxysy.entity.fabao.FabaoSixiangAttribute;
import cn.edu.sgu.www.mhxysy.entity.fabao.FabaoSixiangAttributeCategory;
import cn.edu.sgu.www.mhxysy.entity.fabao.FabaoSixiangType;
import cn.edu.sgu.www.mhxysy.mapper.fabao.FabaoSixiangAttributeCategoryMapper;
import cn.edu.sgu.www.mhxysy.mapper.fabao.FabaoSixiangAttributeMapper;
import cn.edu.sgu.www.mhxysy.mapper.fabao.FabaoSixiangTypeMapper;
import cn.edu.sgu.www.mhxysy.service.fabao.FabaoSixiangAttributeService;
import cn.edu.sgu.www.mhxysy.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Service
public class FabaoSixiangAttributeServiceImpl implements FabaoSixiangAttributeService {

    private final FabaoSixiangTypeMapper fabaoSixiangTypeMapper;
    private final FabaoSixiangAttributeMapper fabaoSixiangAttributeMapper;
    private final FabaoSixiangAttributeCategoryMapper fabaoSixiangAttributeCategoryMapper;

    @Autowired
    public FabaoSixiangAttributeServiceImpl(
            FabaoSixiangTypeMapper fabaoSixiangTypeMapper,
            FabaoSixiangAttributeMapper fabaoSixiangAttributeMapper,
            FabaoSixiangAttributeCategoryMapper fabaoSixiangAttributeCategoryMapper) {
        this.fabaoSixiangTypeMapper = fabaoSixiangTypeMapper;
        this.fabaoSixiangAttributeMapper = fabaoSixiangAttributeMapper;
        this.fabaoSixiangAttributeCategoryMapper = fabaoSixiangAttributeCategoryMapper;
    }

    @Override
    public Map<String, String> selectByFabaoId(String fabaoId) {
        // 查询法宝四象属性
        QueryWrapper<FabaoSixiangAttribute> queryWrapper = new QueryWrapper<>();

        queryWrapper.eq(
                StringUtils.isNotEmpty(fabaoId),
                "fabao_id", fabaoId
        );

        FabaoSixiangAttribute fabaoSixiangAttribute = fabaoSixiangAttributeMapper.selectOne(queryWrapper);

        if (fabaoSixiangAttribute != null) {
            Integer sixiangId = fabaoSixiangAttribute.getSixiangId();
            FabaoSixiangAttributeCategory fabaoSixiangAttributeCategory = fabaoSixiangAttributeCategoryMapper.selectById(sixiangId);
            FabaoSixiangType fabaoSixiangType = fabaoSixiangTypeMapper.selectById(fabaoSixiangAttributeCategory.getType());

            // 构建返回值对象
            Map<String, String> resultMap = new HashMap<>();

            resultMap.put("value", fabaoSixiangAttributeCategory.getEffect());
            resultMap.put("name", fabaoSixiangType.getName());

            return resultMap;
        }

        return null;
    }

}